package com.database.controller;

import com.rent.common.api.ApiString;
import com.rent.common.pojo.ResultJSON;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.Serializable;
import java.util.List;

/**
 * @Author zhang
 * @create 2022/9/12 11:15
 */

public interface DeleteController<T, PK extends Serializable> extends BaseController<T, PK> {


    default ResultJSON<String> delete(@PathVariable PK id) {
        if (id == null) return ResultJSON.failure(ApiString.paramsIllegal);
        int i = getSuperService().deleteByPrimaryKey(id);
        if (0 == i) return ResultJSON.failure(ApiString.deleteFail);
        return ResultJSON.success(ApiString.deleteSuccess);
    }

    default ResultJSON<String> deleteBatchByIds(@RequestParam("keys") List<PK> keys) {
        if (CollectionUtils.isEmpty(keys)) return ResultJSON.failure(ApiString.paramsIllegal);
        int i = getSuperService().deleteByKeys(keys);
        if (0 == i) return ResultJSON.failure(ApiString.deleteFail);
        return ResultJSON.success(ApiString.deleteSuccess);
    }

}
